<template>
  <!-- 后台搜索框 -->
  <div class="main">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      
    >
      <!-- 常规搜索条件 begin -->
      <el-form-item label="提交时间" prop="createTime">
        <el-date-picker
          v-model="queryParams.submitTimeList"
          type="datetimerange"
          range-separator="至"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          size="small"
          @keyup.enter.native="handleQuery"
          end-placeholder="结束日期"
          :picker-options="pickerOptionQuery"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="提交人" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入"
          clearable
          size="small"
          style="width:100px"
        />
      </el-form-item>
      <el-form-item label="流程状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable>
          <el-option
            v-for="item in dict.type.act_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            style="width:100px"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-select v-model="queryParams.projectName" placeholder="请选择" clearable>
          <el-option
            v-for="item in projectNameInfoList"
            :key="item.value"
            :label="item.projectName"
            :value="item.projectName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="出差事由" prop="tripReason">
        <el-input
          v-model="queryParams.tripReason"
          placeholder="请输入出差事由"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出发地点" prop="originPlace">
        <el-input
          v-model="queryParams.originPlace"
          placeholder="请输入出发地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出差地点" prop="destination">
        <el-input
          v-model="queryParams.destination"
          placeholder="请输入出差地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="出差日期" prop="tripTimeList">
        <el-date-picker
          v-model="queryParams.tripTimeList"
          type="daterange"
          range-separator="至"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          size="small"
          @keyup.enter.native="handleQuery"
          end-placeholder="结束日期"
          :picker-options="pickerOptionQuery"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="出差时长">
        <el-input-number v-model="queryParams.durationMin" :min="1" :max="999999" label="最小值"></el-input-number>天 ~
        <el-input-number v-model="queryParams.durationMax" :min="1" :max="999999" label="最大值"></el-input-number>天
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

      <!-- 本表格相关搜索条件 end -->
    </el-form>

    <!-- 全局操作框 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 查看表格 -->
    <el-table
      :height="height"
      v-loading="loading"
      :data="financeTripApplyList"
      @selection-change="handleSelectionChange"
      :default-sort="{prop:'actBusinessStatus.createTime',order:'descending'}"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="提交时间"
        align="center"
        prop="actBusinessStatus.createTime"
        width="180"
        sortable
      />
      <el-table-column
        label="提交人"
        align="center"
        prop="actBusinessStatus.createBy"
        width="100"
        sortable
      />
      <el-table-column label="项目名称" align="center" prop="projectName" width="180" sortable />
      <el-table-column label="出差事由" align="center" prop="tripReason" width="160" sortable />
      <el-table-column label="出发地点" align="center" prop="originPlace" width="160" sortable />
      <el-table-column label="出差地点" align="center" prop="destination" width="160" sortable />
      <el-table-column label="开始日期" align="center" prop="startDate" width="160" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束日期" align="center" prop="endDate" sortable width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出差时长(天)" align="center" prop="duration" width="160" sortable />
      <el-table-column label="流程状态" align="center" prop="actBusinessStatus.status" sortable>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.act_status" :value="scope.row.actBusinessStatus.status" />
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-if="scope.row.actBusinessStatus.status==='draft' || scope.row.actBusinessStatus.status==='cancel' || scope.row.actBusinessStatus.status==='back'"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-if="(scope.row.actBusinessStatus.status==='draft' || scope.row.actBusinessStatus.status==='cancel' || scope.row.actBusinessStatus.status==='back') && (scope.row.createBy == userId || userId === 'admin' || userId === 'sysadmin')"
          >
            删除
            <!--zhoul只允许申请人本人删除当前可编辑的流程或者admin和sysadmin-->
          </el-button>
          <el-button
            v-if="scope.row.actBusinessStatus.status==='waiting'"
            size="mini"
            type="text"
            icon="el-icon-back"
            @click="cancelProcessApply(scope.row)"
          >撤销</el-button>
          <el-button
            v-if="scope.row.actBusinessStatus.status!=='draft' || scope.row.actBusinessStatus.status==='cancel' || scope.row.actBusinessStatus.status==='back'"
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >查看</el-button>
          <el-button
            v-if="scope.row.actBusinessStatus.status!=='draft' || scope.row.actBusinessStatus.status==='cancel' || scope.row.actBusinessStatus.status==='back'"
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="openPrintView(scope.row)"
          >打印</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改出差申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" v-if="open" width="800px" append-to-body>
      <el-tabs type="border-card">
        <el-tab-pane label="业务单据" v-loading="loading">
          <el-form ref="form" :model="form" :rules="rules" >
            <el-form-item label="编号" prop="number">
              <el-input  v-model="form.numberNum" disabled style="width: 220px;"/>
            </el-form-item>
            <el-form-item label="项目名称" prop="projectName">
              <el-select
                v-model="form.projectName"
                :disabled="title!='添加出差申请'"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in projectNameList"
                  :key="item.projectName"
                  :label="item.projectName"
                  :value="item.projectName"
                ></el-option>
              </el-select>
              <!-- <el-input v-model="form.projectName" placeholder="请输入项目名称" :disabled="isDisabled" /> -->
            </el-form-item>
            <el-form-item label="出发地点" prop="originPlace">
              <el-input
                :disabled="isDisabled"
                v-if="form.originPlace"
                v-model="form.originPlace"
                placeholder="请输入出发地点"
              >
                <i
                  v-if="!isDisabled"
                  slot="suffix"
                  class="el-icon-close"
                  @click="loadMap1()"
                  style="cursor: pointer;"
                ></i>
              </el-input>
              <el-cascader
                v-else
                size="large"
                :options="options"
                v-model="form.originPlace"
                @change="handleChangePlace1"
              ></el-cascader>
            </el-form-item>
            <el-form-item label="出差地点" prop="destination">
              <el-input
                :disabled="isDisabled"
                v-if="form.destination"
                v-model="form.destination"
                placeholder="请输入出差地点"
              >
                <i
                  v-if="!isDisabled"
                  slot="suffix"
                  class="el-icon-close"
                  @click="loadMap2()"
                  style="cursor: pointer;"
                ></i>
              </el-input>
              <el-cascader
                v-else
                size="large"
                :options="options"
                v-model="form.destination"
                @change="handleChangePlace2"
              ></el-cascader>
            </el-form-item>
            <el-form-item label="开始日期" prop="startDate">
              <el-date-picker
                clearable
                v-model="form.startDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择开始日期"
                :disabled="isDisabled"
                @change="dateChanged"
                :picker-options="pickerOptionStart"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="结束日期" prop="endDate">
              <el-date-picker
                clearable
                v-model="form.endDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择结束日期"
                :disabled="isDisabled"
                @change="dateChanged"
                :picker-options="pickerOptionEnd"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="出差时长" prop="duration">
              <el-input
                v-model="form.duration"
                placeholder="出差时长必须大于0"
                :disabled="true"
                style="width: 225px"
              ></el-input>
            </el-form-item>
            <el-form-item label="出差事由" prop="tripReason">
              <el-input v-model="form.tripReason" placeholder="请输入出差事由" :disabled="isDisabled" />
            </el-form-item>
            <el-form-item label="上传图片" prop="attachment">
              <image-upload v-model="form.attachment" :isDisabled="isDisabled" :limit="5" />
            </el-form-item>
          </el-form>
          <div class="dialog-footer" style="float:right" v-if="flag">
            <el-button :loading="buttonLoading" type="info" @click="submitForm('zancun')">暂存</el-button>
            <el-button :loading="buttonLoading" type="primary" @click="submitForm('submit')">提交</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-tab-pane>
        <!-- 审批历史 -->
        <el-tab-pane label="审批历史" v-if="processInstanceId">
          <history ref="historyRef" :processInstanceId="processInstanceId"></history>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <!-- 提交 -->
    <printForm
      ref="printForm"
      form-type="出差申请"
      :form="form"
      :history="history"
      :printObject="printObject"
      :actBusinessStatus="actBusinessStatus"
    ></printForm>
    <verify
      ref="verifyRef"
      @submitCallback="submitCallback"
      :componentName="componentName"
      :taskId="taskId"
      :taskVariables="taskVariables"
      :sendMessage="sendMessage"
    ></verify>
  </div>
</template>

<script>
import printForm from "@/views/components/printForm.vue";
import { getDept } from "@/api/system/role";
import {
  listFinanceTripApply,
  getFinanceTripApply,
  delFinanceTripApply,
  addFinanceTripApply,
  updateFinanceTripApply,
  getProjectList
} from "@/api/oa/financeTripApply";
import processApi from "@/api/workflow/processInst";
import history from "@/components/Process/History";
import verify from "@/components/Process/Verify";
import { listByIds } from "@/api/system/oss";
import dayjs from "dayjs";
import { CodeToText, provinceAndCityData } from "element-china-area-data";
import {parseTime} from "@/utils/ruoyi";

export default {
  name: "TripApply",
  dicts: ["act_status"],
  components: {
    history,
    verify,
    printForm
  },
  props: {
    projectNameInfoList: Array,
    projectNameByList: String
  },
  data() {
    return {
      componentName: "出差申请",
      printObject: [],
      history: [],
      actBusinessStatus: {},
      height: `calc(100% - 88px)`,
      selectedOptions: [],
      options: provinceAndCityData,
      pickerOptionQuery: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      // 出差日期的可选范围
      pickerOptionStart: {
        disabledDate: time => {
          if (this.form.endDate) {
            return time.getTime() > new Date(this.form.endDate).getTime();
          }
          return time.getTime() <= new Date();
        }
      },
      pickerOptionEnd: {
        disabledDate: time => {
          if (this.form.startDate) {
            return time.getTime() < new Date(this.form.startDate).getTime();
          }
          return time.getTime() <= new Date();
        }
      },
      userId: "",
      // 是否允许编辑文本框
      isDisabled: false,
      // 预览列表图片
      previewListResource: true,
      // 流程实例
      processInstanceId: "",
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出差申请表格数据
      financeTripApplyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: undefined, //项目名称
        tripReason: undefined, //出差理由
        originPlace: undefined, //出发地
        destination: undefined, //目的地
        startDate: undefined, //开始日期
        endDate: undefined, //结束日期
        // createBy: undefined, //提交人
        status: "", //流程状态
        submitTimeList: [], //提交时间范围
        tripTimeList: [], //出差时间范围
        durationMin: undefined, //出差时长最小值
        durationMax: undefined //出差时长最大值
      },
      // 表单参数
      form: {},
      flag: true,
      // 表单校验
      rules: {
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        tripReason: [
          { required: true, message: "出差事由不能为空", trigger: "blur" }
        ],
        originPlace: [
          { required: true, message: "出发地点不能为空", trigger: "blur" }
        ],
        destination: [
          { required: true, message: "出差地点不能为空", trigger: "blur" }
        ],
        startDate: [
          { required: true, message: "开始日期不能为空", trigger: "blur" }
        ],
        endDate: [
          { required: true, message: "结束日期不能为空", trigger: "blur" }
        ],
        duration: [
          { required: true, message: "出差时长不能为空", trigger: "blur" },
          {
            type: "number",
            min: 0,
            max: 65535,
            message: "大小要在0到65535",
            trigger: "blur"
          }
        ]
      },
      taskVariables: {}, //流程变量
      taskId: undefined, //任务id
      // 消息提醒
      sendMessage: {},
      processKey: "oa_human_trip",
      imageList: [],
      projectNameList: [],
      dept: "",
      deptId: ""
    };
  },
  mounted() {
    this.$nextTick(() => {
      if (this.projectNameByList) {
        this.handleAdd();
        this.form.projectName = this.projectNameByList;
        this.$emit("deleteProjectName");
      }
      this.getList();
      let formHeight = this.$refs.queryForm.$el.offsetHeight;
      this.height = `calc(100% - ${formHeight}px - 88px)`;
    }, 300);
    window.onresize = () => {
      let formHeight = this.$refs.queryForm.$el.offsetHeight;
      this.height = `calc(100% - ${formHeight}px - 88px)`;
    };
    this.userId = this.$store.state.user.name;

    let roles = this.$store.state.user.roles;
    if (this.$store.state.user.dept) {
      this.deptId = this.userId = this.$store.state.user.dept.deptId;
    }
  },
  created() {},
  methods: {
    async openPrintView(row) {
      const { data } = await getFinanceTripApply(row.id);
      this.form = data;
      this.actBusinessStatus = data.actBusinessStatus;
      const res = await getDept(this.actBusinessStatus.createBy);
      this.actBusinessStatus.deptName = res.data ? res.data.deptName : "";
      const res2 = await processApi.getHistoryInfoList(
        this.actBusinessStatus.processInstanceId
      );
      this.history = res2.data.reverse();
      let attachments = [];
      if (this.form.attachment) {
        const res3 = await listByIds(this.form.attachment);
        attachments = res3.data.map(item => {
          return item.originalName;
        });
      }
      this.printObject = [
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "项目名称"
            },
            {
              colspan: 7,
              align: "left",
              label: this.form.projectName
            }
          ]
        },
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "出发地点"
            },
            {
              colspan: 3,
              align: "left",
              label: this.form.originPlace
            },
            {
              colspan: 1,
              align: "center",
              label: "出差地点"
            },
            {
              colspan: 3,
              align: "left",
              label: this.form.destination
            }
          ]
        },
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "开始日期"
            },
            {
              colspan: 3,
              align: "left",
              label: this.form.startDate
            },
            {
              colspan: 1,
              align: "center",
              label: "结束日期"
            },
            {
              colspan: 3,
              align: "left",
              label: this.form.endDate
            }
          ]
        },
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "出差时长"
            },
            {
              colspan: 7,
              align: "left",
              label: this.form.duration + "天"
            }
          ]
        },
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "出差事由"
            },
            {
              colspan: 7,
              align: "left",
              label: this.form.tripReason
            }
          ]
        },
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "上传图片"
            },
            {
              colspan: 7,
              align: "left",
              label: attachments
            }
          ]
        }
      ];
      this.$refs.printForm.open();
    },
    /*行政区划空间选择完毕*/
    loadMap1() {
      this.form.originPlace = "";
      this.selectedOptions = [];
    },
    loadMap2() {
      this.form.destination = "";
      this.selectedOptions = [];
    },
    handleChangePlace1(arr) {
      this.form.originPlace = CodeToText[arr[0]] + "->" + CodeToText[arr[1]];
    },
    handleChangePlace2(arr) {
      this.form.destination = CodeToText[arr[0]] + "->" + CodeToText[arr[1]];
    },
    /*日期范围控件选择完毕*/
    dateChanged() {
      if (this.form.startDate != null && this.form.endDate != null) {
        let val = dayjs(this.form.endDate).diff(
          dayjs(this.form.startDate),
          "days"
        );
        this.form.duration = val < 0 ? val : val + 1;
      }
    },
    /** 查询出差申请列表 */
    getList() {
      this.loading = true;
      listFinanceTripApply(this.queryParams).then(response => {
        this.financeTripApplyList = response.rows;
        this.total = response.total;
        this.loading = false;
        // 替換OSSid
        for (let i = 0; i < this.financeTripApplyList.length; i++) {
          let ossId = this.financeTripApplyList[i].attachment;
          if (ossId != null && ossId.trim().length > 0) {
            let firstOssId = ossId.split(",")[0];
            listByIds(firstOssId).then(response => {
              this.financeTripApplyList[i].attachment = response.data[0].url;
            });
          }
        }
      });
      this.getProjectList();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        projectName: undefined,
        tripReason: undefined,
        originPlace: undefined,
        destination: undefined,
        startDate: undefined,
        endDate: undefined,
        duration: undefined,
        attachment: undefined,
        createTime: undefined,
        updateTime: undefined,
        createBy: undefined,
        updateBy: undefined,
        submitTimeList: [],
        status: undefined
      };
      this.processInstanceId = undefined;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      //时间控件的选择内容
      this.queryParams.pageNum = 1;
      //出差日期范围
      if (
        this.queryParams.tripTimeList != null &&
        this.queryParams.tripTimeList.length > 0
      ) {
        this.queryParams.startDate = this.queryParams.tripTimeList[0];
        this.queryParams.endDate = this.queryParams.tripTimeList[1];
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.submitTimeList = [];
      this.queryParams.tripTimeList = [];
      this.queryParams.durationMin = undefined;
      this.queryParams.durationMax = undefined;
      this.queryParams.startDate = undefined;
      this.queryParams.endDate = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.isDisabled = false;
      this.flag = true;
      this.reset();
      this.open = true;
      this.title = "添加出差申请";
    },
    //查看
    handleView(row) {
      this.flag = false;
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getFinanceTripApply(id).then(response => {
        this.loading = false;
        this.form = response.data;
        if (response.data.actBusinessStatus.createTime){
          this.form.numberNum=this.processKey + '@' + parseTime(response.data.actBusinessStatus.createTime, '{y}{m}{d}{h}{i}{s}')
        }
        this.$nextTick(() => {
          this.processInstanceId =
            response.data.actBusinessStatus.processInstanceId;
        });
        this.isDisabled = true;
        this.open = true;
        this.title = "查看出差申请";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.isDisabled = false;
      this.flag = true;
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getFinanceTripApply(id).then(response => {
        this.loading = false;
        this.form = response.data;
        if (response.data.actBusinessStatus.createTime){
          this.form.numberNum=this.processKey + '@' + parseTime(response.data.actBusinessStatus.createTime, '{y}{m}{d}{h}{i}{s}')
        }
        this.$nextTick(() => {
          this.processInstanceId =
            response.data.actBusinessStatus.processInstanceId;
        });
        this.open = true;
        this.title = "修改出差申请";
      });
    },
    /** 提交按钮 */
    submitForm(flag) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateFinanceTripApply(this.form)
              .then(response => {
                this.$modal.msgSuccess("修改成功");
                if (flag === "submit") {
                  this.submitFormApply(response.data);
                }
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addFinanceTripApply(this.form)
              .then(response => {
                this.$modal.msgSuccess("新增成功");
                if (flag === "submit") {
                  this.submitFormApply(response.data);
                } else {
                  this.open = false;
                }
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    // 提交成功回调
    submitCallback() {
      this.open = false;
      this.getList();
    },
    //提交流程
    submitFormApply(entity) {
      //流程变量
      this.taskVariables = {
        entity: entity,
        deptId: this.deptId
      };
      const data = {
        processKey: this.processKey, // key
        businessKey: entity.id, // 业务id
        variables: this.taskVariables
      };
      this.sendMessage = {
        title: "出差申请",
        messageContent: this.$store.state.user.nickName + "提交了出差申请"
      };
      // 启动流程
      processApi.startProcessApply(data).then(response => {
        this.taskId = response.data.taskId;
        this.$refs.verifyRef.visible = true;
        this.$refs.verifyRef.reset();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除出差申请编号为"' + ids + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delFinanceTripApply(ids);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 全部导出按钮操作 */
    handleExport() {
      this.download(
        "oa/financeTripApply/export",
        {
          ...this.queryParams
        },
        `financeTripApply_${new Date().getTime()}.xlsx`
      );
    },
    //撤回
    cancelProcessApply(row) {
      this.$modal
        .confirm("是否撤销申请")
        .then(() => {
          this.loading = true;
          return processApi.cancelProcessApply(
            row.actBusinessStatus.processInstanceId
          );
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("撤回成功");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    getProjectList() {
      getProjectList().then(res => {
        this.projectNameList = res.data;
      });
    }
  }
};
</script>
<style scoped>
.main {
  width: 100%;
  height: 100%;
}
/* 设置滚动条宽度和高度 */
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 8px; /* 横向滚动条 */
  height: 8px; /* 纵向滚动条 必写 */
}
/* 设置滚动条样式 */
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  background-color: #dde;
  border-radius: 3px;
}
</style>
